package handler

import (
	"2301a/awesomezouProjectye4/api/request"
	"2301a/awesomezouProjectye4/internal/dao"
	"2301a/awesomezouProjectye4/internal/model"
	"github.com/gin-gonic/gin"
	"net/http"
)

func ReleaseComment(c *gin.Context) {
	var req request.ReleaseCommentReq

	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "参数信息错误",
			"data": err.Error(),
		})
		return
	}
	var goods model.Goods
	if goods.Id == 0 {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "该商品不存在",
			"data": nil,
		})
		return
	}
	dao.Create(&model.Comment{
		GoodsId:  req.GoodsId,
		UserId:   req.UserId,
		Content:  req.Content,
		FatherId: req.FatherId,
	})
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "添加评论成功",
		"data": true,
	})
}

func ListComment(c *gin.Context) {
	var req request.ListCommentReq

	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "参数信息错误",
			"data": err.Error(),
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "列表成功",
		"data": true,
	})
}

func DetailsComment(c *gin.Context) {
	var req request.DetailsCommentReq

	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "参数信息错误",
			"data": err.Error(),
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "详情成功",
		"data": true,
	})
}

func RemoveComment(c *gin.Context) {
	var req request.RemoveCommentReq

	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "参数信息错误",
			"data": err.Error(),
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "删除成功",
		"data": true,
	})
}
